package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dot.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {
    @Autowired
    IWmChannelService wmChannelService;
    @PostMapping(value = "/list",name = "根据名称分页查询查询")
    @ApiOperation(value = "/list",notes = "根据名称分页查询查询")
    @ApiImplicitParam(name = "dto",value = "查询",required = true,dataType = "ChannelDto")
    public ResponseResult list (@RequestBody ChannelDto dto){

        return wmChannelService.listByName(dto);
    }


    @PostMapping(name = "新增")
    @ApiOperation(value = "saveChannel",notes = "新增")
    @ApiImplicitParam(name = "channel",value = "频道对象",required = true,dataType = "WmChannel")
    public ResponseResult saveChannel(@RequestBody WmChannel entity){

        return wmChannelService.saveChannel(entity);
    }
    /**
     * 查询所有的频道
     *
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult channels() {
        List<WmChannel> list = wmChannelService.list();
        return ResponseResult.okResult(list);
    }
}
